package com.spring.transaction;


import java.sql.Connection;

/**
 * 多线程事务同步管理
 *
 * 确保每个线程拿到的都是自己的 事务
 */
public class TransactionSynchronizationManager {
	private static final ThreadLocal<Connection> resources = new ThreadLocal<>();
	
	
	public static void bindConnection(Connection conn){
		resources.set(conn);
	}
	
	public static Connection getResource(){
		Connection connection = resources.get();
		return connection;
	}
	
	public static void clear(){
		resources.remove();   // 移除当前线程绑定的connection
	}
}
